import re

import os, sys

pwd = os.path.dirname(os.path.realpath(__file__))
sys.path.append(pwd + '../')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'riscv_build_dataset.settings')

import django

django.setup()

from fedora.models import koji_build
from tqdm import tqdm

def fix_tag():
    builds = koji_build.objects.all()

    for b in tqdm(builds):
        nvr = b.nvr
        tag = re.findall("fc\d{2}", nvr)
        if tag:
            tag = tag[-1]
        else:
            tag = None
        b.tag = tag

    koji_build.objects.bulk_update(builds, ['tag'], 10000)
    # koji_build.objects.abulk_create(builds, ['tag'], 10000)



if __name__ == '__main__':
    fix_tag()